<template>
    <div>
        <ToolBar>

            <div>
                <el-input placeholder="请输入用户编号" size="small" style="width: 140px" v-model="searchParams.userId" clearable>
                </el-input>

                <el-button type="success" size="small" @click="refresh()">查询</el-button>
                <el-button type="warning" size="small" @click="clearSearchParams()">重置</el-button>
            </div>
        </ToolBar>
        <el-table :data="tableData" border style="width: 100%">
            <el-table-column prop="logId" label="日志编号"></el-table-column>
            <el-table-column prop="userId" label="用户编号"></el-table-column>
            <el-table-column prop="logContent" label="内容"></el-table-column>
            <el-table-column prop="ipAddress" label="IP地址"></el-table-column>
            <el-table-column prop="os" label="系统"></el-table-column>
            <el-table-column prop="ie" label="浏览器"></el-table-column>
            <el-table-column prop="createData" label="创建日期"></el-table-column>
            <el-table-column prop="remark" label=""></el-table-column>

        </el-table>
        <el-pagination background :page-size="pageSize" layout="prev, pager, next" :total="total"
            @current-change="changePage"></el-pagination>
        <!--    <Pagination-->
        <!--      :params="searchParams"-->
        <!--      :requestFunc="requestFunc"-->
        <!--      ref="pagination"-->
        <!--      @returnData="returnData"-->
        <!--    />-->
        <Edit :showEditDialog="showEditDialog" @close="showEditDialog = false" @success="refresh()" />
    </div>
</template>

<script>
import { list } from "@/api/user/userlist";
import { resetObject } from "@/utils/common";
import { todelUser } from "@/api/user/userlist"
import { log } from "@/api/logManage/log";
import { getLogByUserId } from "@/api/logManage/log"
//import Edit from "./Edit.vue";
export default {
    data() {
        return {
            tableData: [], // 登录日志数据

            pageSize: 10, //每页显示5条
            total: 0, //总条数
            pageNo: 1, //默认当前页码第1页
            searchParams: {
                title: "",

            },
            showEditDialog: false,

            goodsTypeData: [],
            id: null,
            stateValue: 1
        };
    },
    created() {

        this.getTableData();
    },
    methods: {
        getTableData() {
            if(this.searchParams.userId == null){
            log({
                pageNo: this.pageNo,
                pageSize: this.pageSize
            }).then(resp => {
                this.tableData = resp.records;
                this.total = resp.total;
            })
        }
        else{
            getLogByUserId({
                pageNo: this.pageNo,
                pageSize: this.pageSize,
                userId: this.searchParams.userId,
            }).then(resp => {
                this.tableData = resp.records;
                this.total = resp.total;
            })
        }
        },
        changePage(val) {
            //val:改变页码当前的页码
            this.pageNo = val;
            this.getTableData(); //根据新的页码选取分页数据
        },
        initData() {
            list() // 调用接口或者其他方法来获取登录日志数据，传入用户编号作为参数
                .then(r => {
                    console.log(r);
                    this.tableData = r;
                    //   this.total = r.count;
                })
                .catch(() => { });
        },
        editItem(id) {
            this.id = id;
            this.showEditDialog = true;
        },

        refresh() {
            this.getTableData(this.searchParams.userId);
        },
        returnData(pageList) {
            this.tableData = pageList.list;
        },
        clearSearchParams() {
            resetObject(this.searchParams);
            this.refresh();
        },
        updateState(id, newstate) {
            if (newstate == 0) {
                //删除
                this.$confirm("确定删除?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                })
                    .then(() => {
                        console.log(id);
                        todelUser({ "id": id });
                        this.initData();
                    })
                    .catch(() => { });
            }
        },
        updateStateApi(id, newstate) {
            console.log(id, newstate);

            // row.d = 0;
            // updateStatus({ id: row.id})
            //   .then(r => {
            //     this.$message({
            //       type: "success",
            //       message: "操作成功!"
            //     });
            //     this.refresh();
            //   })
            //   .catch(() => {});
        }
    },


};
</script>
